package chu.dejian.entity;

import java.util.ArrayList;
import java.util.List;

import chu.dejian.db.SendedRequestDao;
import chu.dejian.widget.AttentionLevelView;

/**
 * Created by Administrator on 2016/7/3 0003.
 */
public class SendedRequestEntity {
    public int arId;
    public String attendee;
    public String attendeeName;
    public int attendeeLevel;
    public int status;

    // 0：等待处理，1：接受，2：拒绝，3：超时
    public static final int STATUS_CONSENTED = 1;
    public static final int STATUS_PENDING = 0;
    public static final int STATUS_REFUSED = 2;
    public static final int STATUS_TIMEOUT = 3;

    public static ContactEntity convertToContactEntity(SendedRequestEntity requestEntity){
        ContactEntity contactEntity = new ContactEntity();
        contactEntity.id = requestEntity.arId;
        contactEntity.contactName = requestEntity.attendeeName;
        contactEntity.contactPhoneNum = requestEntity.attendee;
        contactEntity.attentionLevel = AttentionLevelView.ATTENTION_LEVEL.fromInt(requestEntity.attendeeLevel);
        contactEntity.attentionStatus = requestEntity.status;
        return contactEntity;
    }

    public static List<ContactEntity> convertToContactEntity(List<SendedRequestEntity> receivedRequests){
        if(receivedRequests == null) return null;
        List<ContactEntity> contactEntities = new ArrayList<>();
        for(SendedRequestEntity request : receivedRequests){
            contactEntities.add(convertToContactEntity(request));
        }
        return contactEntities;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof SendedRequestEntity)) return false;

        SendedRequestEntity that = (SendedRequestEntity) o;

        if (attendeeLevel != that.attendeeLevel) return false;
        if (status != that.status) return false;
        if (!attendee.equals(that.attendee)) return false;
        return attendeeName.equals(that.attendeeName);

    }

    @Override
    public int hashCode() {
        int result = attendee.hashCode();
        result = 31 * result + attendeeName.hashCode();
        result = 31 * result + attendeeLevel;
        result = 31 * result + status;
        return result;
    }
}
